﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Security.Cryptography;
using System.Text;

public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    private void checkLogin(string username, string password)
    {
        User u = new User();        
        u.Password = password;
        password = u.Encrypt_Pass();
       

        if (!u.checkLogin(username, password))
            mpOKMsg.ShowMessage("Login fail!");
        else
        {
            Session["username"] = u.UserName;
            Session["email"] = u.Email;
            Session["fullname"] = u.FullName;
            Session["groupid"] = u.GroupID;
            Session["phongbanid"] = u.PhongBanID;
            Session["tenphongban"] = u.TenPhongBan;

            if (u.GroupID==1)
                Response.Redirect("index.aspx");
            if (u.GroupID == 2) 
                Response.Redirect("manager/index.aspx");
            if (u.GroupID == 3)
                Response.Redirect("admin/index.aspx");
        }

    }

    protected void btnLogin_Click(object sender, EventArgs e)
    {

        if (txtUserName.Text == "")
            mpOKMsg.ShowMessage("Please enter username.");
        else if (txtPassword.Text == "")
            mpOKMsg.ShowMessage("Please enter password.");
        else checkLogin(txtUserName.Text, txtPassword.Text);
    }
    protected void lForgotPassword_Click(object sender, EventArgs e)
    {
        Response.Redirect("users/get_password.aspx");
    }
    protected void btnRegister_Click(object sender, EventArgs e)
    {

        Response.Redirect("users/register.aspx");
    }
}
